package com.orcsystem.search.config;
import org.apache.http.HttpHost;
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @CreateData: 2020/11/11-13:31
 * Author   AiHongSen
 * 方法说明
 * SL 查询、DL 删除、UP 更新、IN 新增方法
 * OrcsystemElasticSearchConfig->作用:  elasticSearch 配置类
 * 1.导入依赖
 * 2.编写配置  创建配置类 向容器内注入一个RestHighLevelClient
 * 3.
 */
@Configuration
public class OrcsystemElasticSearchConfig {

    public static final RequestOptions COMMON_OPTIONS;
    /**
     * 参考文档给出的通用配置项
     * https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.x/java-rest-low-usage-requests.html#java-rest-low-usage-request-options
     */
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//        builder.addHeader("Authorization", "Bearer " + TOKEN);
//        builder.setHttpAsyncResponseConsumerFactory(
//                new HttpAsyncResponseConsumerFactory
//                        .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }

    @Bean
    public RestHighLevelClient esReastClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("114.116.100.68", 9200, "http")
                )
        );
        return client;
    }
}
